package main

import (
	"fmt"
	"log"
	"os"
)

func main() {
	/*
		遍历文件夹:
	*/
	dirName := "E:/代码文件/灰太狼"
	listFiles(dirName, 0)
}

func listFiles(dirName string, level int) {
	//level用来记录当前递归的层次，生成带有层次感的空格
	s := "|--"
	for i := 0; i < level; i++ {
		s = "|  " + s
	}
	fileInfos, err := os.ReadDir(dirName)
	if err != nil {
		log.Fatal(err)
	}
	for _, fi := range fileInfos {
		fileName := dirName + "/" + fi.Name()
		fmt.Printf("%s%s\n", s, fileName)
		if fi.IsDir() {
			//递归调用的方法
			listFiles(fileName, level+1)
		}
	}
}
